package models;

import com.google.api.services.datastore.DatastoreV1.CommitRequest;
import com.google.api.services.datastore.DatastoreV1.Mutation;

import entities.Domain;

public class DS_DomainModel {

	public static boolean insertDatastore(Domain d) {
		try {		
			CommitRequest.Builder creq = CommitRequest.newBuilder();
			creq.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);

			creq.setMutation(Mutation.newBuilder().addInsert(
					DS_Config.objectToDatastoreEntity(d, d.getName())));

			DS_Config.getDatastore().commit(creq.build());
			System.out.println("Insert success datastore domain - " + d.getName());
		} catch (Exception e) {
			System.out.println("Insert fail datastore domain - " + d.getName() + " - "
					+ e.getMessage());
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public static boolean isExistDomain(String domainName) {
		return false;
	}
}